package graph.weight;

/**
 * 有权无向边
 */
public class Edge implements Comparable<Edge> {
    private final int v;
    private final int w;
    private final double weight;

    public Edge(int v, int w, double weight) {
        this.v = v;
        this.w = w;
        this.weight = weight;
    }

    public double weight() {
        return weight;
    }

    //获取边上的一个点
    public int either() {
        return v;
    }

    //获取边上除了顶点vertex外的另外一个顶点
    public int other(int vertex) {
        if (vertex == v) {
            //如果传入的顶点vertext是v，则返回另外一个顶点w
            return w;
        } else {
            //如果传入的顶点vertext不是v，则返回v即可
            return v;
        }
    }


    @Override
    public int compareTo(Edge o) {
        if (weight > o.weight()) {
            return 1;
        } else if (weight == o.weight) {
            return 0;
        } else {
            return -1;
        }
    }
}
